#include <iostream>

// include nyu header
#include <nyu/nyu.hpp>

// user defined function
nyu::Value my_func(nyu::Context& c) {
    std::cout << __FUNCTION__ << std::endl;

    for (int i = 0; i < c.currentArgc(); i++) {
        std::cout << "[" << i << "]: ";

        nyu::Value v = c.currentArgv(i);
        switch (nyu::value_tag(v)) {
        case nyu::VALUE_TAG_INT:
            std::cout << "INT(" << nyu::value_to_int(v) << ")";
            break;

        case nyu::VALUE_TAG_OBJECT:
            if (nyu::is_null(v)) {
                std::cout << "(null)";
            } else {
                nyu::Handle<nyu::String> s(nyu::value_to_object(v)->toString(c));
                std::cout << s->strval();
            }
            break;
        }

        std::cout << std::endl;
    }

    return nyu::NULL_VALUE;
}

int main() {
    // create context
    nyu::Context c;

    // register function
    c.putFunction("my_func", my_func);

    // execute script
    nyu::Handle<nyu::Value> v(c.evalString("my_func(12345); my_func('abc', {})"));

    return 0;
}
